/**
 * Created by Coing on 2017/2/26.
 */
public class Solution {

    public int lengthOfLastWord(String s) {

        if(s==null|| "".equals(s.trim())){
            return 0;
        }
        // 去掉空格后的全部长度
        String  trim_str = s.trim();
        int Wlength = trim_str.length();
        System.out.println("Wlength: " + Wlength);
        /**
         *  去掉空格后，中间空格所在位置
         */
        int llength = trim_str.lastIndexOf(" ");
        System.out.println("llength: " + llength);
        // 减去空格的位置-1
        int lengthOfLastWord = Wlength - llength - 1;
        System.out.println("lengthOfLastWord: " + lengthOfLastWord);
        return lengthOfLastWord;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.lengthOfLastWord(""));
        System.out.println("**********");
        System.out.println(solution.lengthOfLastWord("  "));
        System.out.println("**********");
        System.out.println(solution.lengthOfLastWord("hello world"));
        System.out.println("**********");
        System.out.println(solution.lengthOfLastWord("  lls  sd 32 "));

    }

}
